package com.budwk.app.sqfwV2.enums.jinYang;

import com.budwk.app.sqfwDoc.codeGenerator.excelGenerate.BaseTemplateExcelGenerator;
import com.budwk.app.sqfwV2.generator.centuryCitySecurity.excel.NineSmallPlacesNewGenerator;
import com.budwk.app.sqfwV2.generator.centuryCitySecurity.excel.V2.GasUseStatisticsGeneratorV2;
import com.budwk.app.sqfwV2.generator.centuryCitySecurity.excel.V2.NineSmallPlacesNewGeneratorV2;
import lombok.Getter;

import java.util.Arrays;
import java.util.Optional;

@Getter
public enum JinYangExcelEnum {
    GAS_USE_STATISTICS("gas_use_statistics_jin_yang", new GasUseStatisticsGeneratorV2(), "", "sqfwV2/jinYang/gasUseStatistics.xlsx", "九小场所", true, "【燃气使用情况统计表】", "全部数据 | 燃料使用情况", "/preview/safety/jinYang/gasUseStatistics.png",false),
    JIN_YANG_NINE_SMALL_PLACE("century_city_nine_small_places_gover_jin_yang", new NineSmallPlacesNewGeneratorV2(), "", "sqfwV2/jinYang/nineSmallPlaces_jin_yang.xlsx", "九小场所", true, "【九小场所安全生产问题隐患清单】", "部分数据|九小场所","/preview/safety/jinYang/九小图_excel.png",true),

    ;

    private final String code;

    private final BaseTemplateExcelGenerator service;

    private final String name;

    private final String templatePath;

    private final String type;

    private final boolean loop;

    private final String fileName;

    private final String label;

    private final String previewImage;

    private final boolean isUseOriginalMethod;//跟基础类相同文件的情况下，判断是否使用原有的处理方式，true-是，false-否


    JinYangExcelEnum(String code, BaseTemplateExcelGenerator service, String name, String templatePath, String type, boolean loop, String fileName, String label, String previewImage,boolean isUseOriginalMethod) {
        this.code = code;
        this.service = service;
        this.name = name;
        this.templatePath = templatePath;
        this.type = type;
        this.loop = loop;
        this.fileName = fileName;
        this.label = label;
        this.previewImage = previewImage;
        this.isUseOriginalMethod = isUseOriginalMethod;
    }

    /**
     * @param code
     * @return
     */
    public static BaseTemplateExcelGenerator getService(String code) {
        Optional<JinYangExcelEnum> optional = Arrays.stream(JinYangExcelEnum.values()).filter(c -> code.equals(c.getCode())).findFirst();
        return optional.map(JinYangExcelEnum::getService).orElse(null);
    }

    /**
     * @param code
     * @return
     */
    public static String getType(String code) {
        for (JinYangExcelEnum o : JinYangExcelEnum.values()) {
            if (o.getCode().equals(code)) {
                return o.getType();
            }
        }
        return null;
    }

    /**
     * @param code
     * @return
     */
    public static JinYangExcelEnum getJinYangEnum(String code) {
        for (JinYangExcelEnum o : JinYangExcelEnum.values()) {
            if (o.getCode().equals(code)) {
                return o;
            }
        }
        return null;
    }

    /**
     * @param code
     * @return
     */
    public static JinYangExcelEnum getJinYangEnumBySplit(String code) {
        for (JinYangExcelEnum o : JinYangExcelEnum.values()) {
            String codeSplit = o.getCode().split("_jin_yang")[0];
            if (codeSplit.equals(code)) {
                return o;
            }
        }
        return null;
    }

    /**
     * @param code
     * @return
     */
    public static String getLabel(String code) {
        Optional<JinYangExcelEnum> optional = Arrays.stream(values()).filter(e -> e.getCode().equals(code)).findFirst();
        return optional.map(JinYangExcelEnum::getLabel).orElse(null);
    }

    /**
     * @param code
     * @return
     */
    public static String getFileName(String code) {
        Optional<JinYangExcelEnum> optional = Arrays.stream(values()).filter(e -> e.getCode().equals(code)).findFirst();
        return optional.map(JinYangExcelEnum::getFileName).orElse(null);
    }

    /**
     * @param type
     * @return
     */
    public static String getCodeByType(String type) {
        Optional<JinYangExcelEnum> optional = Arrays.stream(values()).filter(e -> e.getType().equals(type)).findFirst();
        return optional.map(JinYangExcelEnum::getCode).orElse(null);
    }
}
